home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / REALITY / atom / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  10.7 KB  |  507 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /* menu.c
  18.  * ------
  19.  *
  20.  * $Revision: 1.8 $
  21.  *
  22.  */
  23.  
  24. #include <string.h>
  25. #include <gl/gl.h>
  26. #include <string.h>
  27. #include <gl/sphere.h>
  28.  
  29. #include "mview.h"
  30. #include "geom.h"
  31.  
  32. #define MAX_ENTRIES 15
  33. #define MAX_MENU_ENTRY 100
  34.  
  35. /****************************************************************************/
  36.  
  37. static int BuildModelMenu();
  38. static int BuildAtomMenu();
  39. static int BuildBondMenu();
  40. static int BuildSphereTypeMenu();
  41. static int BuildSpherePrimMenu();
  42. static int BuildBondSmoothMenu();
  43. static int BuildKernelMenu();
  44.  
  45. static void SetFastDraw();
  46. static void SetDispAtoms();
  47. static void SetDispBonds();
  48. static void SetSphereType();
  49. static void SetSpherePrim();
  50. static void SetAtomAccBuf();
  51. static void SetBondAccBuf();
  52. static void SetBondEndCorrect();
  53. static void SetSpinMode();
  54. static void SetRollMode();
  55. static void SetBondSmooth();
  56. static void SetPanel();
  57. static void Reset();
  58. static void Exit();
  59. static void SetModel();
  60. static void SetKernel();
  61.  
  62. /****************************************************************************/
  63.  
  64. void addtopupx(menu, entry, index, current)
  65.     int menu;
  66.     char *entry;
  67.     int index;
  68.     int current;
  69. {
  70.     char new[MAX_MENU_ENTRY];
  71.  
  72.     if (index == current)
  73.     sprintf(new, "*%s %%x%d", entry, index);
  74.     else
  75.     sprintf(new, "%s %%x%d", entry, index);
  76.     addtopup(menu, new);
  77. }
  78.  
  79. void build_long_menu(names, size, current, main_menu, index, basename_flag)
  80.     char **names;
  81.     int size, current;
  82.     int main_menu;
  83.     long index;
  84.     int basename_flag;
  85. {
  86.     int    sub_menu;
  87.     int    i;
  88.     char entry[MAX_MENU_ENTRY], *s;
  89.  
  90.     for (i = 0; i < size; i++) {
  91.     if ((i != 0) && ((i % MAX_ENTRIES) == 0)) main_menu = sub_menu;
  92.     if (((size - i) > MAX_ENTRIES) &&
  93.         ((i % MAX_ENTRIES) == 0)) {
  94.         sub_menu = defpup("Items %t");
  95.         addtopup(main_menu, "More %m", sub_menu);
  96.     }
  97.         if (basename_flag) {
  98.         if (s = strrchr(names[i], '/'))
  99.         s++;
  100.         else
  101.         s = names[i];
  102.     } else
  103.         s = names[i];
  104.  
  105.         addtopupx(main_menu, s, index++, current);
  106.     }
  107. }
  108.  
  109. void BuildMainMenu()
  110. {
  111.     char str[200];
  112.     long sub_menu;
  113.  
  114.     if (Menu != -1)
  115.     freepup(Menu);
  116.  
  117.     sprintf(str, "%s %%t", ProgName);
  118.     Menu = defpup(str);
  119.     if (UsePanel)
  120.     addtopup(Menu, "Close Panel %f", SetPanel);
  121.     else
  122.     addtopup(Menu, "Open Panel %f", SetPanel);
  123.     addtopup(Menu, "Models %m", BuildModelMenu());
  124.     addtopup(Menu, "Kernels %m", BuildKernelMenu());
  125.     addtopup(Menu, "Reset %f", Reset);
  126.     if (FastDraw)
  127.     addtopup(Menu, "Draw Quick off %f", SetFastDraw);
  128.     else
  129.     addtopup(Menu, "Draw Quick on %f", SetFastDraw);
  130.     addtopup(Menu, "Atom %m", BuildAtomMenu());
  131.     /* ZoomFactor */
  132.     addtopup(Menu, "Bond %m", BuildBondMenu());
  133.     addtopup(Menu, "Help %f", DoHelp);
  134.     addtopup(Menu, "Exit %f", Exit);
  135. }
  136.  
  137. static int BuildModelMenu()
  138. {
  139.     static long menu = -1;
  140.  
  141.     if (menu != -1)
  142.     freepup(menu);
  143.     menu = defpup("Models %t %F", SetModel);
  144.  
  145.     build_long_menu(ModelNames, NumModels, ModelId, menu, 0, 0);
  146.     return menu;
  147. }
  148.  
  149. static int BuildKernelMenu()
  150. {
  151.     static long menu = -1;
  152.  
  153.     if (menu != -1)
  154.     freepup(menu);
  155.     menu = defpup("Kernels %t %F", SetKernel);
  156.     InitKernels();
  157.     build_long_menu(Kernels, NumKernels, KernelId, menu, 0, 0);
  158.     return menu;
  159. }
  160.  
  161. static int BuildAtomMenu()
  162. {
  163.     static long menu = -1;
  164.  
  165.     if (menu != -1)
  166.     freepup(menu);
  167.     menu = defpup("Atom %t");
  168.     if (DispAtoms)
  169.     addtopup(menu, "Display off %f", SetDispAtoms);
  170.     else
  171.     addtopup(menu, "Display on %f", SetDispAtoms);
  172.     addtopup(menu, "Sphere Type %m", BuildSphereTypeMenu());
  173.     addtopup(menu, "Sphere Primitive %m", BuildSpherePrimMenu());
  174.     /* XXX SphereDepth */
  175.     if (AtomAccBuf)
  176.     addtopup(menu, "AccBuf off %f", SetAtomAccBuf);
  177.     else
  178.     addtopup(menu, "AccBuf on %f", SetAtomAccBuf);
  179.     if (SpinMode)
  180.     addtopup(menu, "SpinMode off %f", SetSpinMode);
  181.     else
  182.     addtopup(menu, "SpinMode on %f", SetSpinMode);
  183.     if (RollMode)
  184.     addtopup(menu, "RollMode off %f", SetRollMode);
  185.     else
  186.     addtopup(menu, "RollMode on %f", SetRollMode);
  187.     /* XXX RadScaleFactor */
  188.     return menu;
  189. }
  190.  
  191. static int BuildSphereTypeMenu()
  192. {
  193.     static long menu = -1;
  194.  
  195.     if (menu != -1)
  196.     freepup(menu);
  197.     menu = defpup("Sphere Type %t %F", SetSphereType);
  198.     addtopupx(menu, "oct", SPH_OCT, SphereType);
  199.     addtopupx(menu, "icos", SPH_ICOS, SphereType);
  200.     addtopupx(menu, "cube", SPH_CUBE, SphereType);
  201.     addtopupx(menu, "bary", SPH_BARY, SphereType);
  202.     addtopupx(menu, "bilin", SPH_BILIN, SphereType);
  203.     return menu;
  204. }
  205.  
  206. static int BuildSpherePrimMenu()
  207. {
  208.     static long menu = -1;
  209.  
  210.     if (menu != -1)
  211.     freepup(menu);
  212.     menu = defpup("Sphere Prim %t %F", SetSpherePrim);
  213.     addtopupx(menu, "mesh", SPH_MESH, SpherePrim);
  214.     addtopupx(menu, "poly", SPH_POLY, SpherePrim);
  215.     addtopupx(menu, "line", SPH_LINE, SpherePrim);
  216.     addtopupx(menu, "point", SPH_POINT, SpherePrim);
  217.     return menu;
  218. }
  219.  
  220. static int BuildBondMenu()
  221. {
  222.     static long menu = -1;
  223.  
  224.     if (menu != -1)
  225.     freepup(menu);
  226.     menu = defpup("Bond %t");
  227.     if (DispBonds)
  228.     addtopup(menu, "Display off %f", SetDispBonds);
  229.     else
  230.     addtopup(menu, "Display on %f", SetDispBonds);
  231.     if (BondAccBuf)
  232.     addtopup(menu, "AccBuf off %f", SetBondAccBuf);
  233.     else
  234.     addtopup(menu, "AccBuf on %f", SetBondAccBuf);
  235.     addtopup(menu, "Smooth %m", BuildBondSmoothMenu());
  236.     if (BondEndCorrect)
  237.     addtopup(menu, "EndCorrect off %f", SetBondEndCorrect);
  238.     else
  239.     addtopup(menu, "EndCorrect on %f", SetBondEndCorrect);
  240.     return menu;
  241. }
  242.  
  243. static int BuildBondSmoothMenu()
  244. {
  245.     static long menu = -1;
  246.  
  247.     if (menu != -1)
  248.     freepup(menu);
  249.     menu = defpup("Smooth %t %F", SetBondSmooth);
  250.     addtopupx(menu, "Off", SML_OFF, BondSmooth);
  251.     addtopupx(menu, "On", SML_ON, BondSmooth);
  252.     addtopupx(menu, "Smoother", SML_SMOOTHER, BondSmooth);
  253.     return menu;
  254. }
  255.  
  256. static void SetFastDraw()
  257. {
  258.     FastDraw = 1 - FastDraw;
  259.  
  260.     if (FastDraw) {
  261.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  262.     !Alreadyaccumulated)
  263.         DisplayAccScene();
  264.     else
  265.         DisplayScene();
  266.     } else {
  267.     BondSmooth = SML_OFF;
  268.     BondEndCorrect = SML_OFF;
  269.     DoLineSmooth();
  270.     BondAccBuf = 0;
  271.     AtomAccBuf = 0;
  272.     DisplayScene();
  273.     }
  274.  
  275.     if (UsePanel)
  276.     DrawPanel();
  277. }
  278.  
  279. static void SetDispAtoms()
  280. {
  281.     DispAtoms = 1 - DispAtoms;
  282.  
  283.     if ((AtomAccBuf || (DispBonds && BondAccBuf)) && !Alreadyaccumulated)
  284.     DisplayAccScene();
  285.     else
  286.     DisplayScene();
  287.     if (UsePanel)
  288.     DrawPanel();
  289. }
  290.  
  291. static void SetDispBonds()
  292. {
  293.     DispBonds = 1 - DispBonds;
  294.  
  295.     if (((DispAtoms && AtomAccBuf) || BondAccBuf) && !Alreadyaccumulated)
  296.     DisplayAccScene();
  297.     else
  298.     DisplayScene();
  299.     if (UsePanel)
  300.     DrawPanel();
  301. }
  302.  
  303. static void SetSphereType(index)
  304.     long index;
  305. {
  306.     SphereType = index;
  307.     sphmode(SPH_TESS, SphereType);
  308.     CalcInfo();
  309.  
  310.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  311.     !Alreadyaccumulated)
  312.     DisplayAccScene();
  313.     else
  314.     DisplayScene();
  315.     if (UsePanel)
  316.     DrawPanel();
  317. }
  318.  
  319. static void SetSpherePrim(index)
  320.     long index;
  321. {
  322.     SpherePrim = index;
  323.     sphmode(SPH_PRIM, SpherePrim);
  324.     CalcInfo();
  325.  
  326.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  327.     !Alreadyaccumulated)
  328.     DisplayAccScene();
  329.     else
  330.     DisplayScene();
  331.     if (UsePanel)
  332.     DrawPanel();
  333. }
  334.  
  335. static void SetAtomAccBuf(index)
  336.     long index;
  337. {
  338.     AtomAccBuf = 1 - AtomAccBuf;
  339.     if (AtomAccBuf) {
  340.     InitAccBuf();
  341.     if ((DispAtoms || (DispBonds && BondAccBuf)) && !Alreadyaccumulated)
  342.         DisplayAccScene();
  343.     else
  344.         DisplayScene();
  345.     } else {
  346.     if ((DispBonds && BondAccBuf) && !Alreadyaccumulated)
  347.     DisplayAccScene();
  348.     else
  349.     DisplayScene();
  350.     }
  351.  
  352.     if (UsePanel)
  353.     DrawPanel();
  354. }
  355.  
  356. static void SetSpinMode(index)
  357.     long index;
  358. {
  359.     SpinMode = 1 - SpinMode;
  360.  
  361.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  362.     !Alreadyaccumulated)
  363.     DisplayAccScene();
  364.     else
  365.     DisplayScene();
  366.     if (UsePanel)
  367.     DrawPanel();
  368. }
  369.  
  370. static void SetRollMode(index)
  371.     long index;
  372. {
  373.     RollMode = 1 - RollMode;
  374.  
  375.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  376.     !Alreadyaccumulated)
  377.     DisplayAccScene();
  378.     else
  379.     DisplayScene();
  380.     if (UsePanel)
  381.     DrawPanel();
  382. }
  383.  
  384. static void Exit(index)
  385.     long index;
  386. {
  387.     DoExit(0);
  388. }
  389.  
  390. static void Reset(index)
  391.     long index;
  392. {
  393.     DoReset();
  394.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  395.     !Alreadyaccumulated)
  396.     DisplayAccScene();
  397.     else
  398.     DisplayScene();
  399.     if (UsePanel)
  400.     DrawPanel();
  401. }
  402.  
  403. static void SetBondAccBuf(index)
  404.     long index;
  405. {
  406.     BondAccBuf = 1 - BondAccBuf;
  407.  
  408.     if (BondAccBuf) {
  409.     InitAccBuf();
  410.  
  411.     if (((DispAtoms && AtomAccBuf) || BondAccBuf) && !Alreadyaccumulated)
  412.         DisplayAccScene();
  413.     else
  414.         DisplayScene();
  415.     } else {
  416.     if ((DispAtoms && AtomAccBuf) && !Alreadyaccumulated)
  417.         DisplayAccScene();
  418.     else
  419.         DisplayScene();
  420.     }
  421.     if (UsePanel)
  422.     DrawPanel();
  423. }
  424.  
  425. static void SetBondSmooth(index)
  426.     long index;
  427. {
  428.     BondSmooth = index;
  429.     DoLineSmooth();
  430.  
  431.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  432.     !Alreadyaccumulated)
  433.     DisplayAccScene();
  434.     else
  435.     DisplayScene();
  436.  
  437.     if (UsePanel)
  438.     DrawPanel();
  439. }
  440.  
  441. static void SetBondEndCorrect(index)
  442.     long index;
  443. {
  444.     BondEndCorrect = 1 - BondEndCorrect;
  445.     DoLineSmooth();
  446.  
  447.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  448.     !Alreadyaccumulated)
  449.     DisplayAccScene();
  450.     else
  451.     DisplayScene();
  452.  
  453.     if (UsePanel)
  454.     DrawPanel();
  455. }
  456.  
  457. static void SetPanel(index)
  458.     int index;
  459. {
  460.     UsePanel = 1 - UsePanel;
  461.     if (UsePanel) {
  462.     OpenPanelWindow();
  463.     DrawPanel();
  464.     } else {
  465.     ClosePanelWindow();
  466.     }
  467. }
  468.  
  469. static void SetModel(index)
  470.     int index;
  471. {
  472.     ModelId = index;
  473.     SetGeomTitle();
  474.     InitData();
  475.     CalcInfo();
  476.  
  477.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  478.     !Alreadyaccumulated)
  479.     DisplayAccScene();
  480.     else
  481.     DisplayScene();
  482.  
  483.     if (UsePanel)
  484.     DrawPanel();
  485. }
  486.  
  487. static void SetKernel(index)
  488.     int index;
  489. {
  490.     KernelId = index;
  491.     if (KernelFile)
  492.     free (KernelFile);
  493.     KernelFile = strdup(get_basename(Kernels[KernelId]));
  494.     if (ReadKernel(Kernels[KernelId]) == -1)
  495.     return;
  496.  
  497.     if (((DispAtoms && AtomAccBuf) || (DispBonds && BondAccBuf)) &&
  498.     !Alreadyaccumulated)
  499.     DisplayAccScene();
  500.     else
  501.     DisplayScene();
  502.  
  503.     if (UsePanel)
  504.     DrawPanel();
  505. }
  506.  
  507.